<!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js webgl - materials - TIFF texture</title>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<link type="text/css" rel="stylesheet" href="main.css">
	</head>
	<body>
		<div id="info">
			<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - TIFF texture loader</a>
		</div>

		<script type="importmap">
			{
				"imports": {
					"three": "../build/three.module.js",
					"three/addons/": "./jsm/"
				}
			}
		</script>

		<script type="module">

			import * as THREE from 'three';

			import { TIFFLoader } from 'three/addons/loaders/TIFFLoader.js';

			let renderer, scene, camera;

			init();

			function init() {

				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.01, 10 );
				camera.position.set( 0, 0, 4 );

				renderer = new THREE.WebGLRenderer( { antialias: true } );
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				document.body.appendChild( renderer.domElement );

				scene = new THREE.Scene();

				const loader = new TIFFLoader();

				const geometry = new THREE.PlaneGeometry();

				// uncompressed

				loader.load( 'textures/tiff/crate_uncompressed.tif', function ( texture ) {

					texture.colorSpace = THREE.SRGBColorSpace;

					const material = new THREE.MeshBasicMaterial( { map: texture } );

					const mesh = new THREE.Mesh( geometry, material );
					mesh.position.set( - 1.5, 0, 0 );

					scene.add( mesh );

					render();

				} );

				// LZW

				loader.load( 'textures/tiff/crate_lzw.tif', function ( texture ) {

					texture.colorSpace = THREE.SRGBColorSpace;

					const material = new THREE.MeshBasicMaterial( { map: texture } );

					const mesh = new THREE.Mesh( geometry, material );
					mesh.position.set( 0, 0, 0 );

					scene.add( mesh );

					render();

				} );

				// JPEG

				loader.load( 'textures/tiff/crate_jpeg.tif', function ( texture ) {

					texture.colorSpace = THREE.SRGBColorSpace;

					const material = new THREE.MeshBasicMaterial( { map: texture } );

					const mesh = new THREE.Mesh( geometry, material );
					mesh.position.set( 1.5, 0, 0 );

					scene.add( mesh );

					render();

				} );

				//

				window.addEventListener( 'resize', onWindowResize );

			}

			function onWindowResize() {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

				renderer.setSize( window.innerWidth, window.innerHeight );

				render();

			}


			//

			function render() {

				renderer.render( scene, camera );

			}

		</script>
	</body>
</html>
